<template>
  <div class="consensus-activity-integrate">
    <c-title :text="text"></c-title>
    <div v-if="type==3 || type==1" class="head-yuan" :class="{'between':(type==1&&yuan_withdraw_open==0)}">
      <div style="margin-bottom: 1.25rem;">
          <p class="left">当前{{ text }}</p>
          <p class="left count">{{ count }}</p>
      </div>
      <div :class="type==3?'evenly':'center'" v-if="(type==1&&yuan_withdraw_open==1)||type==3">
        <router-link tag="div" :to="fun.getUrl('consensus_activity_withdraw', { num: type })" style="min-width: 4.625rem;">
          <van-button  round size="small"  block color="#F15353">{{type==1?'提现':`转入${yuan_name}`}}</van-button>
        </router-link>
        <router-link tag="div" :to="fun.getUrl('consensus_activity_withdraw', { num: type==3?4:5,open:yuan_to_income_deduct_open })" style="margin:0 0.9375rem;min-width: 4.625rem;">
          <van-button  round size="small"  plain  block color="#F15353">{{type==3?'会员转让':`转入${income_name}`}}</van-button>
        </router-link>
        <template v-if="type==3 ">
          <router-link tag="div" :to="fun.getUrl('consensus_activity_withdraw', { num: 6 })" style="min-width: 4.625rem;">
            <van-button  round size="small"  plain block  color="#F15353">提现</van-button>
          </router-link>
        </template>
      </div>
      <div v-else-if="type==1&&yuan_withdraw_open==0">
        <router-link tag="div" :to="fun.getUrl('consensus_activity_withdraw', { num: 5,open:yuan_to_income_deduct_open })" style="min-width: 4.625rem;">
          <van-button  round size="small"  block color="#F15353">{{`转入${income_name}`}}</van-button>
        </router-link>
      </div>
    </div>
    <div v-else class="head">
      <div>
        <template v-if="type == 6 || type == 5 || type == 4">
          <p v-if="type == 6">奖励总额：{{ count }}</p>
          <p v-else-if="type == 5">当前加权分红额度：{{ count }}</p>
          <p v-else>当前{{text}}：{{ count }}</p>
        </template>
        <template v-else>
          <p class="left">当前{{ text }}</p>
          <p class="left count">{{ count }}</p>
        </template>
      </div>
      <router-link tag="div" :to="fun.getUrl('consensus_activity_withdraw', { num: type })" style="min-width: 4.625rem;"
        v-if="type == 1 || type == 2 ">
        <van-button color="#F15353" round size="small" block>{{ type == 1 ? "提现" : type == 2 ? "会员转让" : '转入元积分'
        }}</van-button>
      </router-link>
    </div>
    <p class="tips">明细记录</p>
    <div class="list" v-if="list && list.length !== 0">
      <div class="box" v-for="(item, i) in list" :key="i">
        <div class="between">
          <span class="bold fz28" v-if="type !== 6">
            {{ item.source_name }}
          </span>
          <template v-if="type == 6">
            <p class="c-AAAAB3" style="text-align: left;">{{ item.created_at }}</p>
          </template>
          <span v-else :class="item.change_value > 0 ? 'plus' : 'minus'">{{ item.change_value }}</span>
        </div>
        <div class="between c-00001c mt-26" v-if="type == 6">
          <div>
            <p style="text-align: left;">个人额度：{{ item.user_weight_quota }}</p>
            <p style="text-align: left;">奖励比例：{{ item.rate }}%</p>
          </div>
          <div class="right">
            <p>加权分红总额度：{{ item.total_weight_quota }}</p>
            <p class="c-F15353">奖励数量：{{ item.reward_value }}</p>
          </div>
        </div>
        <div v-else-if="type==1" class="box-bottom between">
          <template v-if="item.has_one_order || item.has_one_activity">
           <span v-if="item.has_one_order">{{  item.has_one_order&& item.has_one_order.order_sn }}</span>
           <span v-if="item.has_one_activity">
            {{  item.has_one_activity&&item.has_one_activity.activity_name }}
            【{{ item.has_one_activity&&item.has_one_activity.activity_sn  }}】
          </span>
          </template>
          <span>{{ item.created_at }}</span>
        </div>
        <div v-else-if="type==3" class="box-bottom between">
          <div class="hidden">
            <span>{{ item.mark }}</span>
          </div>
          <span style="flex-shrink: 0;">{{ item.created_at }}</span>
        </div>
        <div v-else class="box-bottom between">
          <span>{{ item.created_at }}</span>
        </div>
        <div class="line" v-if="i + 1 !== list.length"></div>
      </div>
    </div>
  </div>
</template>

<script>
import { scrollMixin } from '../../utils/mixin';
export default {
  mixins: [scrollMixin],
  data() {
    return {
      page: 1,
      total_page: 1,
      list: [],
      isLoadMore: true,



      yuan_name:'收益积分',
      count: 0,
      text: "",
      yuan_withdraw_open:null,
      yuan_to_income_deduct_open:0,
      type: null,//1-元积分、2-元积分提现配额、3-收益积分、4-质积分、5-加权分红额度、6-加权分红

    };
  },
  activated() {
    this.type = Number(this.$route.params.num);
    if(this.$route.params.count){
      this.count =this.$route.params.count;
    }
    this.isLoadMore = true;
    if (this.type == 5) {
      this.text = "加权分红额度";
      this.fun.setWXTitle("加权分红额度");
      this.get_dividend_log();
    } else if (this.type == 6) { //加权分红
      this.get_dividend_log();
      this.text = "加权分红";
      this.fun.setWXTitle("加权分红");
    } else {
      this.getData();
    }
  },
  methods: {
    get_dividend_log(page = 1) {
      let url = "plugin.wise-yuan-trade.frontend.my.add-weighted-dividend-log";
      if(this.type == 5){
        url = 'plugin.wise-yuan-trade.frontend.my.add-weighted-dividend-limit-log';
      }
      $http.get(url, { page }, '').then(res => {
        this.isLoadMore = true;
        if (res.result) {
          let data = res.data;
          this.page = data.current_page;
          this.total_page = data.last_page;
          (page == 1) ? (this.list = data.data) : (this.list.concat(data.data));
          if(this.type==6){
            this.count = data.total_reward_value;
          }
        } else {
          this.$toast(res.msg);
        }
      })
    },
    getMoreData() {
      this.isLoadMore = false;
      if (this.page >= this.total_page) {
        return;
      }
      let page = this.page + 1;
      if(this.type==6){
        this.get_dividend_log(page);
      }else{
        this.get_point_record(page);
      }
    },
    getData() {
      let url = "plugin.wise-yuan-trade.frontend.my.custom-name";
      if(this.type == 4){
        url = 'plugin.wise-yuan-trade.frontend.quality.index';
      }
      $http.get(url, "", "").then(res => {
        if (res.result) {
          let data = res.data;
          let type = Number(this.$route.params.num);
          let text = "";
          if (type == 1) {
            text = data.yuan_name;
            this.income_name = data.income_name;
          } else if (type == 2) {
            text = data.yuan_withdraw_limit_name;
          } else if (type == 3) {
            text = data.income_name;
          } else if (type == 4) {
            text = data.quality_name;
            this.count = data.quality;
          }
          this.text = text;
          this.fun.setWXTitle(text);
          if(this.type == 4){
            this.get_point_record();
          }else{
            this.get_detail();
          }
        } else {
          this.$toast(res.msg);
        }
      })
    },
    get_point_record(page = 1) {
      let url = 'plugin.wise-yuan-trade.frontend.yuan-point.record';
      if (this.type == 2) {
        url = "plugin.wise-yuan-trade.frontend.yuan-point.quota-record";
      } else if (this.type == 3) {
        url = 'plugin.wise-yuan-trade.frontend.income-point.record';
      }else if(this.type == 4){
        url = 'plugin.wise-yuan-trade.frontend.quality.record';
      }
      $http.get(url, { page }, "").then(res => {
        this.isLoadMore = true;
        if (res.result) {
          let data = res.data;
          (page==1)?(this.list=data.data):(this.list=this.list.concat(data.data));
          this.page = data.current_page;
          this.total_page = data.last_page;
        } else {
          this.$toast(res.msg);
        }
      })
    },
    get_detail() {
      let url = "";
      if (this.type == 1 || this.type == 2) {
        url = 'plugin.wise-yuan-trade.frontend.yuan-point.index';
      } else if (this.type == 3) {
        url = 'plugin.wise-yuan-trade.frontend.income-point.index';
      }
      $http.get(url, "", "").then(res => {
        if (res.result) {
          let data = res.data;
          if (this.type == 1 || this.type == 2) {
            if (this.type == 1) {
              this.count = data.usable_yuan;
              this.yuan_withdraw_open = data.yuan_withdraw_open;
              this.yuan_to_income_deduct_open = data.yuan_to_income_deduct_open;
            } else {
              this.count = data.yuan_withdraw_quota;
            }
          }else if(this.type == 3){
            this.yuan_name = data.yuan_name;
            this.count = data.income;
          }
          this.get_point_record();
        } else {
          this.$toast(res.msg);
        }
      })
    },
  }
};
</script>

<style scoped lang="scss">
.consensus-activity-integrate {
  padding: 0.625rem 0.75rem;

    .evenly{
      display: flex;
      align-items: center;
      justify-content: space-evenly;
    }
  .hidden {
    overflow-x: scroll;
    white-space: nowrap;
    margin-right: 0.625rem;
  }

  .hidden::-webkit-scrollbar {
    display: none;
  }

  .plus {
    font-weight: bold;
    color: #f15353;
  }

  .minus {
    font-weight: bold;
    color: #00001c;
  }

  .c-F15353 {
    color: #f15353;
  }

  .c-00001c {
    color: #00001c !important;
  }

  .mt-26 {
    margin-top: 0.8125rem;
  }

  .c-AAAAB3 {
    color: #aaaab3;
  }

  .right {
    text-align: right;
  }

  .list {
    background: #fff;
    padding: 0.9375rem 0.75rem;
    border-radius: 0.625rem;
  }
  .head-yuan{
    padding: 0.9375rem 0.75rem;
    background: #fff;
    border-radius: 0.625rem;
  }
  .center{
    display: flex;align-items: center;justify-content: center;
  }
  .between {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .fz28 {
    font-size: 0.875rem;
  }

  .bold {
    font-weight: bold;
  }

  .line {
    width: 100%;
    height: 1px;
    background: #ccc;
    margin: 1.0625rem 0 0.9375rem;
  }

  .box-bottom {
    margin-top: 0.5rem;
    color: #aaaab3;
    font-size: 0.75rem;
  }

  .tips {
    margin: 0.875rem 0.75rem;
    font-weight: bold;
    font-size: 0.9375rem;
    text-align: left;
  }

  .left {
    text-align: left;
  }

  .count {
    font-weight: bold;
    font-size: 1.5rem;
  }

  .head {
    padding: 0.9375rem 0.75rem;
    background: #fff;
    border-radius: 0.625rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
